#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string compressString(string S) {
        if (S.length() == 0) return S;
        int count = 1;
        string sp;
        char ch = S[0];
        for (int i = 1; i < S.length(); i++) {
            if (ch == S[i])   count++;
            else {
                sp += ch + to_string(count);
                ch = S[i];
                count = 1;
            }
        }
        sp += ch + to_string(count);
        return S.length() > sp.length() ? sp : S;
    }
};